package org.gesplan.entity;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author David
 */
@Entity
@Table(name = "work")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Work.findAll", query = "SELECT w FROM Work w"),
    @NamedQuery(name = "Work.findById", query = "SELECT w FROM Work w WHERE w.id = :id"),
    @NamedQuery(name = "Work.findByDateWork", query = "SELECT w FROM Work w WHERE w.dateWork = :dateWork"),
    @NamedQuery(name = "Work.findByTimeElapsed", query = "SELECT w FROM Work w WHERE w.timeElapsed = :timeElapsed"),
})
public class Work implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "date_work")
    @Temporal(TemporalType.DATE)
    private Date dateWork;
    @JoinColumn(name = "staff_id", referencedColumnName = "id")
    @ManyToOne
    private Staff staffId;
    @JoinColumn(name = "task_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Task taskId;
    @JoinColumn(name = "section_id", referencedColumnName = "id")
    @ManyToOne
    private Section sectionId;    
    @Basic(optional = false)
    @Column(name = "time_elapsed")
    private float timeElapsed;
    @Column(name = "worked")
    private float worked;
    @Column(name = "extra_to_charge")
    private float extraToCharge;    
    @Column(name = "extra_to_recover")
    private float extraToRecover;
    @Column(name = "extra_recovered")
    private float extraRecovered;
    @Column(name = "vacation")
    private float vacation;
    @Column(name = "disable")
    private float disable;
    @Column(name = "syndicate")
    private float syndicate;
    @Column(name = "comments")
    private String comments;
    @Column(name = "location")
    private String location;    
    @OneToMany(mappedBy = "workId")
    private Collection<WorkLocation> workLocationCollection;
    
    
    public Work() { }

    public Work(Integer id) {
        this.id = id;
    }

    public Work(Integer id, Date dateWork, float timeElapsed) {
        this.id = id;
        this.dateWork = dateWork;
        this.timeElapsed = timeElapsed;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public Date getDateWork() {
        return dateWork;
    }

    public void setDateWork(Date dateWork) {
        Date oldDateWork = this.dateWork;
        this.dateWork = dateWork;
        changeSupport.firePropertyChange("dateWork", oldDateWork, dateWork);
    }

    public Staff getStaffId() {
        return staffId;
    }

    public void setStaffId(Staff staffId) {
        Staff oldStaffId = this.staffId;
        this.staffId = staffId;
        changeSupport.firePropertyChange("staffId", oldStaffId, staffId);
    }
    
    public float getTimeElapsed() {
        return timeElapsed;
    }

    public void setTimeElapsed(float timeElapsed) {
        float oldTimeElapsed = this.timeElapsed;
        this.timeElapsed = timeElapsed;
        changeSupport.firePropertyChange("timeElapsed", oldTimeElapsed, timeElapsed);
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        String oldComments = this.comments;
        this.comments = comments;
        changeSupport.firePropertyChange("comments", oldComments, comments);
    }
    
    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        String oldLocation = this.location;
        this.location = location;
        changeSupport.firePropertyChange("location", oldLocation, location);
    }    

    public Task getTaskId() {
        return taskId;
    }

    public void setTaskId(Task taskId) {
        Task oldTaskId = this.taskId;
        this.taskId = taskId;
        changeSupport.firePropertyChange("taskId", oldTaskId, taskId);
    }
    
    public Section getSectionId() {
        return sectionId;
    }

    public void setSectionId(Section sectionId) {
        Section oldSectionId = this.sectionId;
        this.sectionId = sectionId;
        changeSupport.firePropertyChange("SectionId", oldSectionId, sectionId);
    }    

   
    @XmlTransient
    public Collection<WorkLocation> getWorkLocationCollection() {
        return workLocationCollection;
    }

    public void setWorkLocationCollection(Collection<WorkLocation> workLocationCollection) {
        this.workLocationCollection = workLocationCollection;
    }
    

    public float getWorked() {
        return worked;
    }


    public void setWorked(float worked) {
        this.worked = worked;
    }


    public float getExtraRecovered() {
        return extraRecovered;
    }


    public void setExtraRecovered(float extraRecovered) {
        this.extraRecovered = extraRecovered;
    }

    
    public float getextraToRecover() {
        return extraToRecover;
    }


    public void setExtraToRecover(float extraToRecover) {
        this.extraToRecover = extraToRecover;
    }
    
    public float getExtraToCharge() {
        return extraToCharge;
    }


    public void setExtraToCharge(float extraToCharge) {
        this.extraToCharge = extraToCharge;
    }
    
    
    public float getVacation() {
        return vacation;
    }


    public void setVacation(float vacation) {
        this.vacation = vacation;
    }


    public float getDisable() {
        return disable;
    }


    public void setDisable(float disable) {
        this.disable = disable;
    }


    public float getSyndicate() {
        return syndicate;
    }


    public void setSyndicate(float syndicate) {
        this.syndicate = syndicate;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Work)) {
            return false;
        }
        Work other = (Work) object;
        return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
    }

    @Override
    public String toString() {
        return "org.gesplan.entity.Work[ id=" + id + " ]";
    }
    
    
}